export default {
    namespaced: true,
    
    state: () => ({
        
        // 收货地址
        address: JSON.parse(uni.getStorageSync('address') || '{}'),
        
        // 登录成功够得token字符串
        token: uni.getStorageSync('token') || '',
        
        // 用户的基本信息
        userinfo: JSON.parse(uni.getStorageSync('userinfo') || '{}'),
        
        // 重定向的Object对象
        redirectInfo: null
    }),
    
    mutations: {
        updataAddress(state, address) {
            state.address = address
            this.commit('m_user/saveAddressStorage')
        },
        
        // 持久化存储 address
        saveAddressStorage(state) {
            uni.setStorageSync('address', JSON.stringify(state.address))
        },
        
        updataUserinfo(state, userinfo) {
            state.userinfo = userinfo
            
            this.commit('m_user/saveUserinfoToStorage')
        },
        
        // 持久化存储用户基本信息
        saveUserinfoToStorage(state) {
            uni.setStorageSync('userinfo', JSON.stringify(state.userinfo))
        },
        
        // 将拿到的token放到state中
        updataToken(state, token) {
            state.token = token
            
            this.commit('m_user/saveTokenStorage')
        },
        
        // 持久化存储token
        saveTokenStorage(state) {
            uni.setStorageSync('token',state.token)
        },
        
        updataRedirectInfo(state, info) {
            state.redirectInfo = info
        }
    },
    
    getters: {
        
        addrStr(state) {
            if(!state.address.provinceName) return ''
                
            return state.address.provinceName + state.address.cityName + state.address.countyName + state.address.detailInfo
        }
    }
}